import React from 'react'
// ===================================================================== Declare
const { $fn, $Lazy } = window
// ===================================================================== Lazy
const Table = $Lazy.state(()=>import('@antd/table'))
// ===================================================================== 
const Index =  function(option){
	const opt = {
		type: 0,
		...option
	}
	
	let { type, sort, onSelect, onSelectOk, disabled } = opt
	
	const { data, pagingLoading, pag, selectedKeys, selectedRows, cols } = this.state
	const typeData = [ 'checkbox', 'radio' ]
	const _type = Array.isArray(selectedKeys) ? typeData[ type ] : null
	
	return (
		<Table
			cols			= { $fn.hasArray(cols) ? cols : (this.cols||[]) }
			data 			= { data || this.props.data }
			loading 		= { pagingLoading || this.props.pagingLoading }
			pag				= { pag }
			selectedKeys	= { selectedKeys }
			selectedRows	= { selectedRows }
			onChange		= { (current, pageSize) => $fn.pageChange.call(this,{current, pageSize}) }
			onSelect		= { 
					onSelect ? onSelect : (selectedKeys, selectedRows) =>  { 
						$fn.setKeys.call(this,selectedKeys,selectedRows); 
						onSelectOk?.(selectedKeys,selectedRows) 
					}
			}
			onSort			= { sort ? $fn.onSort.bind(this) : null }
			onRef			= { ref => this.table = ref }
			disabled		= { disabled }
			{ ...option }
			type 			= { _type }
		/>
	)
}
export default Index